/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InsertNewPathDialog.java
 *
 * Created on 16-ago-2009, 11.08.25
 */

package ufofilearchiver.gui;

import java.io.File;
import ufofileorganizer.core.commands.facade.InsertPath;
import ufofileorganizer.core.commands.facade.Save;

/**
 *
 * @author ufo
 */
public class InsertNewPathDialog extends javax.swing.JDialog {

	private static final long serialVersionUID = 1L;
	/** Creates new form InsertNewPathDialog */
    public InsertNewPathDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel_Path = new javax.swing.JLabel();
        jLabel_DiskName = new javax.swing.JLabel();
        jButton_Browse = new javax.swing.JButton();
        jTextField_Path = new javax.swing.JTextField();
        jTextField_DiskName = new javax.swing.JTextField();
        jButton_Close = new javax.swing.JButton();
        jButton_Ok = new javax.swing.JButton();
        jCheckBox_Symlink = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel_Path.setText("Path:");
        jLabel_Path.setName("jLabel_Path"); // NOI18N

        jLabel_DiskName.setText("Disk Name:");
        jLabel_DiskName.setName("jLabel_DiskName"); // NOI18N

        jButton_Browse.setText("Browse");
        jButton_Browse.setName("jButton_Browse"); // NOI18N
        jButton_Browse.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_BrowseMouseClicked(evt);
            }
        });

        jTextField_Path.setName("jTextField_Path"); // NOI18N
        jTextField_Path.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_PathActionPerformed(evt);
            }
        });

        jTextField_DiskName.setName("jTextField_DiskName"); // NOI18N

        jButton_Close.setText("Close");
        jButton_Close.setName("jButton_Close"); // NOI18N
        jButton_Close.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_CloseMouseClicked(evt);
            }
        });

        jButton_Ok.setText("Ok");
        jButton_Ok.setName("jButton_Ok"); // NOI18N
        jButton_Ok.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_OkMouseClicked(evt);
            }
        });

        jCheckBox_Symlink.setText("Don't scan Symlink (only for Unix-like filesystems)");
        jCheckBox_Symlink.setName("jCheckBox_Symlink"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel_DiskName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel_Path, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField_DiskName, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                            .addComponent(jTextField_Path, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                            .addComponent(jCheckBox_Symlink, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)))
                    .addComponent(jButton_Ok, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton_Close, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton_Browse, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_Path, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton_Browse)
                    .addComponent(jTextField_Path, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_DiskName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_DiskName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox_Symlink)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_Close)
                    .addComponent(jButton_Ok))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField_PathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_PathActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_PathActionPerformed

    private void jButton_BrowseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_BrowseMouseClicked
        javax.swing.JFileChooser jFileChooser = new javax.swing.JFileChooser();
        jFileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);// TODO add your handling code here:
        jFileChooser.setVisible(true);
        jFileChooser.showOpenDialog( jButton_Browse );
        jTextField_Path.setText(jFileChooser.getSelectedFile().getAbsolutePath());
    }//GEN-LAST:event_jButton_BrowseMouseClicked

    private void jButton_CloseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_CloseMouseClicked
        setVisible(false);
    }//GEN-LAST:event_jButton_CloseMouseClicked

    private void jButton_OkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_OkMouseClicked
        InsertPath insertPathCommand = new InsertPath(new File(jTextField_Path.getText()), jTextField_DiskName.getText(), "" , jCheckBox_Symlink.isSelected());
        insertPathCommand.execute();
        
        new Save().execute();

        setVisible(false);
    }//GEN-LAST:event_jButton_OkMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                InsertNewPathDialog dialog = new InsertNewPathDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Browse;
    private javax.swing.JButton jButton_Close;
    private javax.swing.JButton jButton_Ok;
    private javax.swing.JCheckBox jCheckBox_Symlink;
    private javax.swing.JLabel jLabel_DiskName;
    private javax.swing.JLabel jLabel_Path;
    private javax.swing.JTextField jTextField_DiskName;
    private javax.swing.JTextField jTextField_Path;
    // End of variables declaration//GEN-END:variables

}
